package com.personalblog.credentials;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.util.SimpleByteSource;

/**
 * 自定义凭证（密码）匹配器
 * @author jxau_scf
 * @date 2021/4/20 - 12:11
 */
public class BugCredentialsMatcher extends SimpleCredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        // 对前台传入的明文数据加密，根据自定义加密规则加密
        Object tokenCredential = new SimpleByteSource((char[]) token.getCredentials());
        //从数据库获取加密数据
        Object accunt = new SimpleByteSource((char[]) info.getCredentials());
        //返回对比结果
        return equals(accunt, tokenCredential);
    }
}
